/**
 * Demo模块状态
 */
import { defineStore } from 'pinia';
import { getDemoData } from '../services';

export const useDemoStore = defineStore('demo', {
  state: () => ({
    loading: false,
    data: [],
  }),

  actions: {
    async fetchData(params: any = {}) {
      this.loading = true;
      try {
        const response = await getDemoData(params);
        this.data = response.data;
        return response;
      } catch (error) {
        console.error('获取demo数据失败:', error);
        return Promise.reject(error);
      } finally {
        this.loading = false;
      }
    },

    resetState() {
      this.loading = false;
      this.data = [];
    }
  }
});
